﻿using KD.Service.HR.Utility;
using Logistics.Model;
using Logistics.Service;
using Logistics.WebApi.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

namespace Logistics.WebApi.Controllers
{
    [MyAuthority]
    public class CompanySaleController : ApiController
    {
        private AccountService accountService = new AccountService();
        private CompanySaleService saleService = new CompanySaleService();
        private CompanyService companyService = new CompanyService();

        [HttpGet]
        public ResponseModel Get()
        {
            var resultmod = new ResponseModel();
            var accountId = Convert.ToInt32(HttpContext.Current.Request.Headers[LogisticsConst.LOGIN_HEADER]);
            try
            {
                int company_id = companyService.GetCompanyIdByAccountId(accountId);
                resultmod.mod = saleService.GetSales(company_id);
                resultmod.InitResultState(GetDataStateEnum.Success);
            }
            catch (Exception ex)
            {
                resultmod.InitResultState(ex);
            }

            return resultmod;
        }

        public ResponseModel Add(wuliu_company_sales_query sale)
        {
            var resultmod = new ResponseModel();
            var accountId = Convert.ToInt32(HttpContext.Current.Request.Headers[LogisticsConst.LOGIN_HEADER]);
            try
            {
                int company_id = companyService.GetCompanyIdByAccountId(accountId);
                sale.company_id = company_id;
                sale.state = "1";
                saleService.Add(sale);
                resultmod.mod = saleService.GetSales(company_id);
                resultmod.InitResultState(StateEnum.Success);
            }
            catch (Exception ex)
            {
                resultmod.InitResultState(ex);
            }

            return resultmod;
        }
    }
}